summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorliamwhite <liamwhite@users.noreply.github.com>2023-10-23 16:33:37 +0200
committerGitHub <noreply@github.com>2023-10-23 16:33:37 +0200
commit1cc764988f47d9fc1663617992402e9d8f39a2e7 (patch)
treef0c4d235d77d02d84361e876c178697cebed478f
parentMerge pull request #11847 from ameerj/glsl-shfl-fix (diff)
parentcheats: Clamp cheat names without failing (diff)
downloadyuzu-1cc764988f47d9fc1663617992402e9d8f39a2e7.tar
yuzu-1cc764988f47d9fc1663617992402e9d8f39a2e7.tar.gz
yuzu-1cc764988f47d9fc1663617992402e9d8f39a2e7.tar.bz2
yuzu-1cc764988f47d9fc1663617992402e9d8f39a2e7.tar.lz
yuzu-1cc764988f47d9fc1663617992402e9d8f39a2e7.tar.xz
yuzu-1cc764988f47d9fc1663617992402e9d8f39a2e7.tar.zst
yuzu-1cc764988f47d9fc1663617992402e9d8f39a2e7.zip
-rw-r--r--src/core/memory/cheat_engine.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/core/memory/cheat_engine.cpp b/src/core/memory/cheat_engine.cpp
index a06e99166..53a89cc8f 100644
--- a/src/core/memory/cheat_engine.cpp
+++ b/src/core/memory/cheat_engine.cpp
@@ -19,16 +19,23 @@ namespace Core::Memory {
namespace {
constexpr auto CHEAT_ENGINE_NS = std::chrono::nanoseconds{1000000000 / 12};
-std::string_view ExtractName(std::string_view data, std::size_t start_index, char match) {
+std::string_view ExtractName(std::size_t& out_name_size, std::string_view data,
+ std::size_t start_index, char match) {
auto end_index = start_index;
while (data[end_index] != match) {
++end_index;
- if (end_index > data.size() ||
- (end_index - start_index - 1) > sizeof(CheatDefinition::readable_name)) {
+ if (end_index > data.size()) {
return {};
}
}
+ out_name_size = end_index - start_index;
+
+ // Clamp name if it's too big
+ if (out_name_size > sizeof(CheatDefinition::readable_name)) {
+ end_index = start_index + sizeof(CheatDefinition::readable_name);
+ }
+
return data.substr(start_index, end_index - start_index);
}
} // Anonymous namespace
@@ -113,7 +120,8 @@ std::vector<CheatEntry> TextCheatParser::Parse(std::string_view data) const {
return {};
}
- const auto name = ExtractName(data, i + 1, '}');
+ std::size_t name_size{};
+ const auto name = ExtractName(name_size, data, i + 1, '}');
if (name.empty()) {
return {};
}
@@ -125,12 +133,13 @@ std::vector<CheatEntry> TextCheatParser::Parse(std::string_view data) const {
.definition.readable_name[out[*current_entry].definition.readable_name.size() - 1] =
'\0';
- i += name.length() + 1;
+ i += name_size + 1;
} else if (data[i] == '[') {
current_entry = out.size();
out.emplace_back();
- const auto name = ExtractName(data, i + 1, ']');
+ std::size_t name_size{};
+ const auto name = ExtractName(name_size, data, i + 1, ']');
if (name.empty()) {
return {};
}
@@ -142,7 +151,7 @@ std::vector<CheatEntry> TextCheatParser::Parse(std::string_view data) const {
.definition.readable_name[out[*current_entry].definition.readable_name.size() - 1] =
'\0';
- i += name.length() + 1;
+ i += name_size + 1;
} else if (::isxdigit(data[i])) {
if (!current_entry || out[*current_entry].definition.num_opcodes >=
out[*current_entry].definition.opcodes.size()) {